/**
 * Copyright (c) 2018 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package com.lswms.modules.job.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

/**
 * 扫描完成任务
 */
@Component("TaskTask")
@Slf4j
public class TaskTask implements ITask{
	private Logger logger = LoggerFactory.getLogger(getClass());

//	@Autowired
//	private TaskDao taskDao;
//	
//	@Autowired
//	private TaskRecordDao taskRecordDao;
//
//    @Autowired
//    private StockInDetailService stockInDetailService;
//
//    @Autowired
//    private StockOutService stockOutService;
//    
//    @Autowired
//    private LocateService locateService;
//    
//    @Autowired
//    private FinishstockinreturnService finishstockinreturnService;
    

	
	@Override
	public void run(String params){
//		logger.debug("TaskTask定时任务正在执行，参数为：{}", params);
//        QueryWrapper<TaskEntity> wrapper = new QueryWrapper<>();
//        wrapper.eq("task_status", 10);
//        List<TaskEntity> list = taskDao.selectList(wrapper);
//        for(TaskEntity task : list) {
//        	if(task.getTaskStatus() == 10) {
//            	//入库完成、10--》上架
//            	if(task.getTaskType() == 1 ) {
//            		OnshelvesDTO dto = new OnshelvesDTO();
//            		dto.setLocate_no(task.getLocateTo());
//            		dto.setTrayCode(task.getTrayFrom());
//            		stockInDetailService.onshelves(dto);
//            		try {
//            			finishstockinreturnService.saveErpFromInfo(task);
//            		}catch(Exception e) {
//            			log.info("入库ERP异常：{}",e);
//            		}
//            	//回库确认，10
//            	}else if(task.getTaskType() == 3) {
//            		stockOutService.backInConfirm(task.getTrayFrom());
//            	//移库确认，10
//            	}else if(task.getTaskType() == 4) {
//            		locateService.moveLocateConfirm(task.getLocateFrom(),task.getLocateTo());
//            	//出库
//            	}else if(task.getTaskType() == 2 && StringUtils.isNotBlank(task.getAgvTo())) {
//                    //目标接口地址
//                    String url = "http://192.168.0.239:8182/rcms/services/rest/hikRpcService/genAgvSchedulingTask";
//                    List<PositionCodePath> lists = new ArrayList<PositionCodePath>();
//                    PositionCodePath path = new PositionCodePath();
//                    path.setPositionCode(task.getAgvFrom());
//                    lists.add(path);
//                    path = new PositionCodePath();
//                    path.setPositionCode(task.getAgvTo());
//                    lists.add(path);
//                    //请求参数JOSN类型
//                    JSONObject postData = new JSONObject();
//                    postData.put("reqCode", task.getTaskId().toString());
//                    postData.put("taskCode", task.getTaskId().toString());
//                    postData.put("taskTyp", "F01");
//                    postData.put("positionCodePath", lists);
//                    RestTemplate client = new RestTemplate();
//                    log.info("参数：{}",JSON.toJSONString(postData));
//                    JSONObject json = client.postForEntity(url, postData, JSONObject.class).getBody();
//                    log.info("返回：{}",JSON.toJSONString(json));
//
//            	}
//            	
//            	if(task.getTaskType() == 1 || task.getTaskType() == 3 || task.getTaskType() == 4 
//            			/*||( task.getTaskType() == 2 && StringUtils.isAllBlank(task.getAgvTo())  )*/) {
//                	//删除task,复制到任务记录表
//                	TaskRecordEntity entity = ConvertUtils.sourceToTarget(task, TaskRecordEntity.class);
//                	int count = taskRecordDao.insert(entity);
//                	if(count > 0) {
//                    	Map<String,Object> map = new HashMap<>();
//                    	map.put("uuid", task.getUuid());
//                    	taskDao.deleteTask(map);
//                	}
//            	}
//        	}
//        }
	}
}